home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Mark MSGS *)
- (* *)
- (* Copyright 1988, 1989 by H. Roy Engehausen. All rights reserved. *)
- (* This software may be freely distributed and used, but it may not *)
- (* under any circumstances be sold by anyone other than the author. *)
- (* It may be distributed by a commercial company as long as it is *)
- (* for no cost. *)
- (* *)
- (*===========================================================================*)
-
- {$O+}
-
- UNIT BBMARK;
-
- INTERFACE
-
- PROCEDURE mark_msgs_old(command : STRING);
-
- IMPLEMENTATION
-
- USES
- DOS,
- bbdummy,
- bbmem,
- bbmf,
- bbsdata,
- bbsearch,
- bbstr,
- bbtime;
-
- (*===========================================================================*)
- (* Procedure to mark things old *)
- (*===========================================================================*)
-
- PROCEDURE mark_msgs_old(command : STRING);
-
- VAR
- code : INTEGER;
- days_to_age : INTEGER;
- date_to_age_to : LONGINT;
- i : BYTE;
- invert_test : BOOLEAN;
- search_block : search_block_type;
- mark_this : BOOLEAN;
- msg_number_str : STRING[5];
- msg_age : LONGINT;
- msg_age_str : STRING[5];
- type_to_use : (unknown, mark_by_bid, mark_by_type, mark_by_search);
- type_aggregate : STRING[27];
- type_to_age : STRING[27];
- word_count : BYTE;
- word_to_do : BYTE;
-
- (*=========================================================================*)
- (* Sub procedure to check on what type of search to do *)
- (*=========================================================================*)
-
- PROCEDURE do_type_select;
-
- BEGIN;
-
- (*---------------------------------------------------------------------*)
- (* See which mark by we want *)
- (*---------------------------------------------------------------------*)
-
- IF type_aggregate = 'BID' THEN
- BEGIN;
- type_to_use := mark_by_bid;
- EXIT;
- END;
-
- IF type_aggregate = 'TYPE' THEN
- BEGIN;
- type_to_use := mark_by_type;
- EXIT;
- END;
-
- IF LENGTH(type_aggregate) = 1 THEN
- BEGIN;
- type_to_use := mark_by_search;
- EXIT;
- END;
-
- type_to_use := unknown;
-
- send_tnc_data_str('Invalid type of search to mark old with' + cr);
-
- END;
-
- (*=========================================================================*)
- (* Sub procedure to mark a message old *)
- (*=========================================================================*)
-
- PROCEDURE do_this_msg;
-
- BEGIN;
-
- WITH search_block.search_last^.msg_i_mb DO
- BEGIN;
-
- IF (msg_flag AND (mf_hold OR mf_old OR mf_kill)) <> 0 THEN
- EXIT;
-
- msg_flag := msg_flag OR mf_old;
- update_msg(search_block.search_last);
- STR(msg_number, msg_number_str);
- msg_age := (last_midnight - msg_dt_in)
- DIV ticks_per_day;
- STR(msg_age, msg_age_str);
- send_tnc_data_str('Message #' + msg_number_str
- + ' marked as old after '
- + msg_age_str + ' days' + cr);
- END;
-
- END;
-
- (*=========================================================================*)
- (* Do by search *)
- (*=========================================================================*)
-
- PROCEDURE do_by_search;
-
- BEGIN;
-
- command := subword(@command, 2, 0);
-
- set_search(command, @search_block);
- IF active_tcb^.error_sw THEN
- EXIT;
-
- search_msg(@search_block);
-
- WHILE search_block.search_last <> NIL DO
- BEGIN;
- do_this_msg;
- search_msg(@search_block);
- END;
-
- free_task_mem('MSB', TRUE);
-
- END;
-
- (*=========================================================================*)
- (* Mark by age or bid *)
- (*=========================================================================*)
-
- PROCEDURE do_type_age;
-
- BEGIN;
-
- (*---------------------------------------------------------------------*)
- (* Get ready to loop thru the info *)
- (*---------------------------------------------------------------------*)
-
- type_aggregate := '';
-
- word_to_do := 3;
-
- (*---------------------------------------------------------------------*)
- (* Loop thru the parms *)
- (*---------------------------------------------------------------------*)
-
- WHILE word_to_do < word_count DO
- BEGIN;
-
- type_to_age := subword(@command, word_to_do + 1, 1);
- VAL(type_to_age, days_to_age, code);
- IF (code <> 0) OR (days_to_age < 1) OR (days_to_age > 300) THEN
- BEGIN;
- STR(word_to_do + 1, type_to_age);
- send_tnc_data_str('Invalid number of days to age -- Parm #'
- + type_to_age);
- EXIT;
- END;
-
- type_to_age := subword(@command, word_to_do, 1);
-
- IF type_to_use = mark_by_bid THEN
- BEGIN;
- i := POS('_', type_to_age);
- IF i <> 0 THEN
- type_to_age[i] := ' ';
- END;
-
- IF (LENGTH(type_to_age) > 27) OR
- ((LENGTH(type_to_age) + LENGTH(type_aggregate))
- >= SIZEOF(type_aggregate)) THEN
- BEGIN;
- STR(word_to_do, type_to_age);
- send_tnc_data_str('Invalid message criteria to age -- Parm #'
- + type_to_age);
- EXIT;
- END;
-
- invert_test := type_to_age = '*';
-
- date_to_age_to := last_midnight -
- (LONGINT(days_to_age) * ticks_per_day);
-
- WITH search_block DO
- BEGIN;
-
- FILLCHAR(search_block, SIZEOF(search_block), #0);
-
- search_last := NIL;
- search_ascend := TRUE;
- search_nok := TRUE;
-
- IF type_to_use = mark_by_type THEN
- BEGIN;
- search_type := 'D';
- search_dt := date_to_age_to;
- END;
-
- IF type_to_use = mark_by_bid THEN
- BEGIN;
- search_type := '$';
- search_str := type_to_age;
- END;
-
- search_msg(@search_block);
-
- WHILE search_last <> NIL DO
- BEGIN;
-
- WITH search_last^.msg_i_mb DO
- BEGIN;
-
- IF (msg_flag AND (mf_hold OR mf_old OR mf_kill)) = 0 THEN
- BEGIN;
-
- IF type_to_use = mark_by_type THEN
- IF NOT invert_test THEN
- mark_this := POS(msg_type, type_to_age) <> 0
- ELSE
- mark_this := POS(msg_type, type_aggregate) = 0;
-
- IF type_to_use = mark_by_bid THEN
- BEGIN;
- mark_this := msg_dt_in < date_to_age_to;
- IF NOT mark_this THEN
- search_last := NIL;
- END;
-
- IF mark_this THEN
- do_this_msg;
-
- END;
-
- END; (*----- End message addressing ---------------------*)
-
- IF search_last <> NIL THEN
- search_msg(@search_block);
-
- END; (*----- End search loop --------------------------------*)
-
- END;
-
- IF type_to_use = mark_by_type THEN
- type_aggregate := type_aggregate + type_to_age;
-
- word_to_do := word_to_do + 2;
-
- END; (*----- End loop thru the parms --------------------------------*)
-
- END;
-
- (*=========================================================================*)
- (* Main line *)
- (*=========================================================================*)
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Break out the command *)
- (*-----------------------------------------------------------------------*)
-
- upcase_str_var(command);
-
- word_count := words(command);
-
- IF word_count < 3 THEN
- BEGIN;
- send_tnc_data_str('Wrong number of parms for old message selection');
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* See which type *)
- (*-----------------------------------------------------------------------*)
-
- type_aggregate := subword(@command, 2, 1);
-
- do_type_select;
-
- IF type_to_use = unknown THEN
- EXIT;
-
- (*-----------------------------------------------------------------------*)
- (* Do some more checking *)
- (*-----------------------------------------------------------------------*)
-
- IF (type_to_use <> mark_by_search)
- AND ((word_count MOD 2) <> 0) OR (word_count < 4) THEN
- BEGIN;
- send_tnc_data_str('Wrong number of parms for old message selection');
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Do the search *)
- (*-----------------------------------------------------------------------*)
-
- send_tnc_data_str('Old message search commencing' + cr);
-
- IF (type_to_use <> mark_by_search) THEN
- do_type_age
- ELSE
- do_by_search;
-
- send_tnc_data_str('Old message search complete' + cr);
-
- END;
-
- END.